import React from 'react'
// ===================================================================== Temp
import SubmitForm from '#cpt/temp/SubmitForm'
// ===================================================================== Declare
const { $fn, $Lazy, $http } = window
// ===================================================================== Lazy
const Page 			= $Lazy.load(()=>import('#tp/page/page-container'))
//
const message 		= $Lazy.file(()=>import('@antd/message'))
const confirm 		= $Lazy.file(()=>import('@antd/confirm'))
const $cache 		= $Lazy.file(()=>import('#private/cache-api'))
 // ===================================================================== component
 class Index extends React.Component{
 	state = {
 		// 提交表单列表
 		formData : [
 			{ label: '项目名称',		name: 'parent_kind',  full:true,	type:'select', onValue:({value, formData})=>{
				formData[0].btn.disabled = !Boolean(value)
				this.setState({ formData })
			}, btn:{ label:'同步项目设置', disabled:true, onClick: value =>{
				$http.submit(null,'ts-report-card/tsUpKind',{ param:{kind_id:value,is_checked:1}, isPull:true }).then(({num})=>{
					confirm.then(f=>{
						f({
							msg:`本次操作将影响 ${num||0} 条数据，是否确认同步检测项目？`,
							onOk: close => {
								$http.submit(null,'ts-report-card/tsUpKind',{ param:{kind_id:value,is_checked:0}}).then(({num})=>{
									close()
									message.then(f=>f.success(`本次同步 ${num} 条数据成功`))
								})
							}
						})
					})
				})
				
			} }, title:'同步项目设置'},
 			{ label: '条码号',		name: 'spec_code', 		full:true,		required:true, title:'补发项目' },
 			{ label: '自然项目',		name: 'parent_kind_id', 			full:true,		required:true, 	type:'select' },
 		]
 	}
 	
 	componentDidMount(){
		this.getSelect()
 	}
 	
	// 获取下拉数据
	getSelect = async () => {
		const { formData } = this.state
		$cache.then( async f => {
			// 项目名称、自然项目
			const _data = await f.getCache({ api:'nature_project' } )
			$fn.setRow(formData, 'parent_kind', _data)
			$fn.setRow(formData, 'parent_kind_id', _data)
			this.setState({ formData })
		})
	}
	
 	render(){
 		return (
 			<>
 				<Page title='项目处理'>
					{
						SubmitForm.call(this,{ 
							contentClassName	: 'plr10',
							okText				: '补发项目',
							labelWidth			: 's5', 
							btnSize				: 'large',
							scroll				: true,
							hideButton			: false,
							api					: 'ts-report-card/repeatKind',
							noEsc				: true,
						}) 
					}
 				</Page>
 			</>
 		)
 	}
 }
 
 export default Index